home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / bpl70n12.zip / ARISOURC.ZIP / FPCMP.ASM < prev    next >
Assembly Source File  |  1993-03-07  |  3KB  |  79 lines

  1.  
  2. ; *******************************************************
  3. ; *                                                     *
  4. ; *     Turbo Pascal Runtime Library Version 7.0        *
  5. ; *     Real Comparison                                 *
  6. ; *                                                     *
  7. ; *     Copyright (C) 1989-1993 Norbert Juffa           *
  8. ; *                                                     *
  9. ; *******************************************************
  10.  
  11.              TITLE   FPCMP
  12.  
  13.  
  14. CODE         SEGMENT BYTE PUBLIC
  15.  
  16.              ASSUME  CS:CODE
  17.  
  18. ; Publics
  19.  
  20.              PUBLIC  CmpMantissa,CmpAbsValue,RCmp
  21.  
  22. ;-------------------------------------------------------------------------------
  23. ; RealCmp compares two numbers in the TURBO-Pascal six byte real format. The
  24. ; flags are set as if two unsigned integers had been compared with the 80x86
  25. ; CMP instruction. If op1 > op2, neither carry nor zero flag are set. If
  26. ; op1 = op2 then the zero flag is set and if op1 < op2 then the carry flag is
  27. ; set. CmpAbsValue is an additional entry to the comparison routine that
  28. ; requires that both arguments are positive. Entry CmpMantissa is provided for
  29. ; arguments that are both positive and have identical exponents.
  30. ;
  31. ; INPUT:     DX:BX:AX  first number (op1)
  32. ;            DI:SI:CX  second number (op2)
  33. ;
  34. ; OUTPUT:    CF        set if op1 < op2
  35. ;            ZF        set if op1 = op2
  36. ;
  37. ; DESTROYS:  Flags
  38. ;-------------------------------------------------------------------------------
  39.  
  40. RCmp         PROC    FAR
  41.              XOR     DX, DI            ; sign equal ?
  42.              JNS     $sign_eq          ; yes
  43.              XOR     DX, DI            ; restore DX
  44.              CMP     DI, DX            ; negative number bigger, reverse compare
  45. $exit1:      RET                       ; exit
  46. $sign_eq:    XOR     DX, DI            ; restore DX
  47.              JNS     $cmp_pos          ; compare exponents and mantissas
  48.              CALL    CmpAbsValue       ; call expo. & mant. compare for neg. num
  49.              JZ      $exit1            ; if numbers equal exit
  50.              CMC                       ; else complement carry flag for neg. num
  51.              RET                       ; done
  52. $cmp_pos:    CALL    CmpAbsValue       ; compare two positive numbers
  53.              RET                       ; done
  54. RCmp         ENDP
  55.  
  56.              ALIGN   4
  57.  
  58. CmpAbsValue  PROC    NEAR
  59.              CMP     AL, CL            ; compare exponents
  60.              JNZ     $end              ; not equal, ->
  61.              OR      AL, AL            ; equal, but both zero ?
  62.              JZ      $end              ; yes
  63. CmpAbsValue  ENDP
  64.  
  65. CmpMantissa  PROC    NEAR
  66.              CMP     DX, DI            ; compare
  67.              JNZ     $end              ;  mantissa bytes
  68.              CMP     BX, SI            ;   from msb
  69.              JNZ     $end              ;    to lsb and exit
  70.              CMP     AH, CH            ;     if unequal or all equal
  71. $end:        RET                       ; done
  72. CmpMantissa  ENDP
  73.  
  74.              ALIGN   4
  75.  
  76. CODE         ENDS
  77.  
  78.              END
  79.